#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/time.h>

int main(int argc, char const *argv[])
{
  
    int fd = open("/dev/driver_hello", O_RDWR);
    printf("file fd: %d \n", fd);
    if(fd < 0) {
        printf("error to open file \n");
    }
    long len = 1024*1024;  //1M
    unsigned char *rbuf = (unsigned char *)malloc(len);
    memset(rbuf, 0x00, len);
    printf("maloc buf: %p \n", rbuf);
    int count = 0;
    struct timeval start, end;
    gettimeofday( &start, NULL);
    long times = 1024 * 10; //1G
    while (times-- > 0)
    {
        count = read(fd, rbuf, len);
    }
    gettimeofday( &end, NULL);
    double duration = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec;

    printf("计时器： %f \n",duration/1000000.0);

    printf("maloc buf: %p \n", rbuf);
    printf("read count: %d \n", count);
    // size_t i = 0;
    // count = 0;
    // for(i = 0; i < len; i++) {
    //     printf("%02x ", rbuf[i]);
    //     if(i % 16 == 0) {
    //         printf("\n");
    //     }
    // }
    // printf("\n");
    return 0;
}

